//package com.javachmapi.springbootjsoup.croner;
//
//import com.api.util.HttpClientUtil;
//import com.llk.utils.AreaHelper;
//import net.sf.json.JSONArray;
//import net.sf.json.JSONObject;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Service;
//import uw.dao.DaoFactory;
//import uw.dao.TransactionException;
//import zwy.saasdataanalysis.constant.ApiConfig;
//import zwy.saasdataanalysis.service.PeptileTaskLog;
//import zwy.saasdataanalysis.tool.DateUtils;
//import zwy.saasdataanalysis.tool.HttpUtil;
//
//import java.text.SimpleDateFormat;
//import java.time.LocalDate;
//import java.time.format.DateTimeFormatter;
//
///**
// * 批量采集云客赞产品
// * @author songlijun
// * @Date: 2019\9\19 0019
// *
// **/
//
//@Service
//public class ReptileYunkezuanTask {
//
//    DaoFactory dao = DaoFactory.getInstance();
//
//    private static final Logger logger = LoggerFactory.getLogger(ReptileYunkezuanTask.class);
//
//    /**
//     * 批量采集云客赞产品
//     */
////    @Scheduled(cron = "0 0 1 * * ?")
////    @SchedulerLock(name = "yunkezuanJob", lockAtLeastFor = 1000 * 30)
//    public void yunkezuanJob() {
//        try {
//            int sum = 0;
//            String state = "0";
//            String size="3000";
//
//            //获取当前系统日期
//            //String sysdate = UWDate.getToday().replace("-","");
//            //获取当前系统日期
//            LocalDate date = LocalDate.now();
//            String sysdate = date.format(DateTimeFormatter.BASIC_ISO_DATE);
//
//            //开始请求
//            String jsonStr = HttpUtil.doGet("http://api.yunkezan.com/apiv2/marketing/getGoodsByTagId?version=1.0.1&system=m&lang=js&APIGEEHEADER2=MTU2OTU4MjAxMyNzeXN0ZW0sdmVyc2lvbixsYW5nLGltZWksI2JpNzU1NWJlNDNlMWEzNjk3MmViNmY3NmZhZGNkMGY4YjJwdXBnaTU%3D&securityKey=2B9ShmcMq3M%2BHWOo5PNuu9i9UMCnM9kV55cRUeDcV1EIvLHkdFaIyNOGJYePaFGGWDi2%2FHZzI%2FB26SkYHq8Di%2BC6cd%2FiGXbPv%2B%2BvDDVIazEV0HhqdQ7Qo9dwmYQ9biGmaT%2FfyKvFzvl4KnHz%2BkWY2duUIihneU1t&page=1&size=" + size, "");
//          logger.info("#####请求返回####"+jsonStr);
//            JSONObject jsonObject = JSONObject.fromObject(jsonStr);
//            //这里判断是否获取得到真实Json对象
//            logger.info("###########开启定时任务批量采集云客赞产品#############");
//            if(jsonObject.getString("code").equals("1000")){ //代表获取成功
//                //得到第一个data对象
//                JSONObject content = null;
//                try {
//                    content = jsonObject.getJSONObject("content");
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//                JSONArray jsonArray = content.getJSONArray("list");
//                for (int z = 1; z <= jsonArray.size(); z++) {
//                    try {
//                        String biz = "云客赞";
//                        String info_id = null;
//                        try {
//                            info_id = jsonArray.getJSONObject(z).getString("goodsId");
////                            if(dao.queryForDataSet(ApiConfig.SAAS_DATA,"select info_id from reptile_product where biz='ykz' and info_id="+info_id).size()>0){
////                                dao.executeCommand(ApiConfig.SAAS_DATA,"insert into reptile_product_ykz_"+sysdate+" (biz,info_id)values(?,?)",
////                                        new Object[]{biz,info_id});
////                                continue;
////                            }
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String link = null;
//                        try {
//                            link = "http://api.yunkezan.com/apiv2/room/couponDetail?version=1.0.1&system=m&lang=js&APIGEEHEADER2=MTU3NDY2MjI5MiNzeXN0ZW0sdmVyc2lvbixsYW5nLGltZWksIzV0MzQwYzQyODgwZmNiYmZhNTlmNDU3Yjk5ZmViYWFjYmQ3bXowd3Y%3D&securityKey=2B9ShmcMq3M%2BHWOo5PNuu9i9UMCnM9kV55cRUeDcV1EIvLHkdFaIyNOGJYePaFGGWDi2%2FHZzI%2FB26SkYHq8Di%2BC6cd%2FiGXbPlxpHipvsPcYraOhxebfUZTP36zkeGfq4AviqlS0XMB%2F1KXQTXG5u2OA6YWrgZX%2BM&weChatId=1&productId="+info_id;
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String info_title = null;
//                        try {
//                            info_title = jsonArray.getJSONObject(z).optString("goodsName");
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String info_name = null;
//                        try {
//                            info_name = jsonArray.getJSONObject(z).optString("productTitle");
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String img = null;
//                        try {
//                            img = jsonArray.getJSONObject(z).optString("poster");
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String out_area_id = null;
//                        try {
//                            out_area_id = jsonArray.getJSONObject(z).optString("provinceCode");
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String province = null;
//                        try {
//                            province = jsonArray.getJSONObject(z).optString("province");
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String city = null;
//                        try {
//                            city = jsonArray.getJSONObject(z).optString("city");
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String area_name = city;
//                        String area_id = null;
//                        try {
//                            area_id = AreaHelper.getAreaIDForName(city);
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String districtName = null;
//                        try {
//                            districtName = jsonArray.getJSONObject(z).optString("districtName");
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String out_area_name=province+"-"+city+"-"+districtName;
//                        String start_date = null;
//                        try {
//                            start_date = DateUtils.secondToDate(jsonArray.getJSONObject(z).getLong("startTime"));
//
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String end_date = null;
//                        try {
//                            end_date = DateUtils.secondToDate(jsonArray.getJSONObject(z).getLong("endTime"));
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String price  = "0";
//                        try {
//                            price = String.valueOf(new Double((Double.valueOf(jsonArray.getJSONObject(z).optString("minPrice"))*100)).intValue());
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String market_price = "0";
//                        try {
//                            market_price = String.valueOf(new Double((Double.valueOf(jsonArray.getJSONObject(z).optString("marketPrice"))*100)).intValue());
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        String address = null;
//                        try {
//                            String xiangqingstr = HttpClientUtil.doGet(link,"");
//                            JSONObject xiangqing = JSONObject.fromObject(xiangqingstr);
//                            address=xiangqing.getJSONObject("content").getString("position");
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        try {
//                            String storage=null;
//                            String tree_name=null;
//                            String order_num=null;
//                            String context = null;
//                            dao.executeCommand(ApiConfig.SAAS_DATA,"insert into reptile_product_ykz_"+sysdate+" (biz,info_id,link,info_title,info_name,img,area_id,area_name,tree_name,start_date,end_date,price,market_price,order_num,address,storage,context,out_area_id,out_area_name)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
//                                    new Object[]{biz,info_id,link,info_title,info_name,img,area_id,area_name,tree_name,start_date,end_date,price,market_price,order_num,address,storage,context,out_area_id,out_area_name});
//                            sum++;
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                    } catch (Exception e) {
//                        PeptileTaskLog.pullproductLog("云客赞","数据不存在"+e.getMessage(),0,"0");
//                    }
//
//                }
//                logger.info("云客赞产品采集完成！一共采集了"+sum+"件产品！");
//                PeptileTaskLog.pullproductLog("云客赞","云客赞采集成功！一共爬取了"+sum+"件产品",sum,"1");
//            }else if(jsonObject.getString("code").equals("1001")){ //代表数据不存在
//                logger.info("云客赞产品采集失败！数据不存在！");
//                PeptileTaskLog.pullproductLog("云客赞","数据不存在",0,state);
//            }
//        } catch (Exception e) {
//            try {
//                PeptileTaskLog.pullproductLog("云客赞","数据不存在"+e.getMessage(),0,"0");
//            } catch (TransactionException e1) {
//                e1.printStackTrace();
//            }
//        }
//    }
//
//    public static void main(String[] args) {
//        System.out.println(DateUtils.secondToDate(1569722400));
//
//        SimpleDateFormat geshihua=new SimpleDateFormat("yyyyMMddHHmmss");
//        String sysdate = geshihua.format(new java.util.Date());
//
//        System.out.println(sysdate);
//    }
//}
